package info.pello.struts2;


import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.ServletActionContext;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;


public class DelegacionAction extends ActionSupport implements ModelDriven<Equipo> {

	private static final long serialVersionUID = -6659354552584240539L;

	
	private Delegacion delegacion = new Delegacion();
	private List<Delegacion> listaDelegacions = new ArrayList<Delegacion>();
	private DelegacionDAO delegacionDAO = new DelegacionDAO();

	
	@Override
	public Delegacion getModel() {
		return delegacion;
	}
	
	/**
	 * To save or update user.
	 * @return String
	 */
	public String guardarOActualizar()
	{	
		delegacionDAO.guardarOActualizarDelegacion(delegacion);
		return SUCCESS;
	}
	
	/**
	 * To list all users.
	 * @return String
	 */
	public String listar()
	{
		listaDelegacions = delegacionDAO.listarDelegacions();
		return SUCCESS;
	}
	
	/**
	 * To delete a user.
	 * @return String
	 */
	public String eliminar()
	{
		HttpServletRequest request = (HttpServletRequest) ActionContext.getContext().get(ServletActionContext.HTTP_REQUEST);
		delegacionDAO.eliminarDelegacion(Long.parseLong(request.getParameter("id")));
		return SUCCESS;
	}
	
	/**
	 * To list a single user by Id.
	 * @return String
	 */
	public String editar()
	{
		HttpServletRequest request = (HttpServletRequest) ActionContext.getContext().get(ServletActionContext.HTTP_REQUEST);
		delegacion = delegacionDAO.listarDelegacionPorId(Long.parseLong(request.getParameter("id")));
		return SUCCESS;
	}
	
	public Delegacion getDelegacion() {
		return delegacion;
	}

	public void setDelegacion(Delegacion delegacion) {
		this.delegacion = delegacion;
	}

	public List<Delegacion> getListaDelegacions() {
		return listaDelegacions;
	}

	public void setListaDelegacions(List<Delegacion> listaDelegacions) {
		this.listaDelegacions = listaDelegacions;
	}
	


}
